{% extends 'food/base.html' %}

{% block content %}
<div class="row">
    <div class="col-md-6">
        <div class="card mb-4">
            <div class="card-header">
                <h5 class="card-title mb-0">食品详情</h5>
            </div>
            <div class="card-body">
                <h4>{{ food.name }}</h4>
                <table class="table">
                    <tr>
                        <th>类别:</th>
                        <td>{{ food.category.name }}</td>
                    </tr>
                    <tr>
                        <th>数量:</th>
                        <td>{{ food.quantity }} {{ food.unit }}</td>
                    </tr>
                    <tr>
                        <th>存储位置:</th>
                        <td>{{ food.storage_location }}</td>
                    </tr>
                    <tr>
                        <th>保质期:</th>
                        <td>{{ food.expiry_date }}</td>
                    </tr>
                </table>
                <a href="{% url 'admin:food_food_change' food.id %}" class="btn btn-primary">编辑</a>
                <a href="{% url 'food:food_list' %}" class="btn btn-secondary">返回列表</a>
            </div>
        </div>
    </div>
    
    <div class="col-md-6">
        <div class="card">
            <div class="card-header d-flex justify-content-between align-items-center">
                <h5 class="card-title mb-0">采购历史</h5>
                <a href="{% url 'admin:food_purchase_add' %}" class="btn btn-primary btn-sm">添加采购记录</a>
            </div>
            <div class="card-body">
                <div class="table-responsive">
                    <table class="table">
                        <thead>
                            <tr>
                                <th>日期</th>
                                <th>数量</th>
                                <th>价格</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for purchase in purchases %}
                            <tr>
                                <td>{{ purchase.purchase_date }}</td>
                                <td>{{ purchase.quantity }} {{ food.unit }}</td>
                                <td>￥{{ purchase.price }}</td>
                            </tr>
                            {% empty %}
                            <tr>
                                <td colspan="3" class="text-center">暂无采购记录</td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
